import i18n from '@/lang'
import { strategyPerms } from '@/config/permission/index'
// 策略列表表头,列带有special属性值为true时，说时需要单独处理单元中的值
export const strategyTbColumns = [
  {
    title: i18n.t('policyName'),
    dataIndex: 'name',
    scopedSlots: { customRender: 'name' },
    special: true,
    width: 300
  }, {
    title: i18n.t('policyStatus'),
    dataIndex: 'used',
    scopedSlots: { customRender: 'used' },
    width: 200
  }, {
    title: i18n.t('timeOfCreation'),
    dataIndex: 'createTime',
    scopedSlots: { customRender: 'createTime' },
    width: 180,
    sorter: true
  }, {
    title: i18n.t('creator'),
    dataIndex: 'createBy',
    scopedSlots: { customRender: 'createBy' },
    width: 120
  }, {
    title: i18n.t('operation'),
    dataIndex: 'action',
    scopedSlots: { customRender: 'action' },
    special: true,
    width: 320,
    fixed: 'right'
  }]
export const strategyTbRowAction = [
  {
    title: i18n.t('edit'),
    key: 'editStrategy',
    getAuth (record, vm) {
      return strategyPerms[vm.versionType][vm.upgradeTriggerType].fotaTjcl.edit
    },
    disabled (record) {
      // 条件策略当已使用或者已停用则不能再编辑
      return (record.used || !record.enabled)
    }
  },
  // 停用策略
  {
    title: i18n.t('disabled'),
    key: 'disabledStrategy',
    disabled (record) {
      // 未使用的则可以停用
      return record.used || !record.enabled
    },
    getAuth (record, vm) {
      return strategyPerms[vm.versionType][vm.upgradeTriggerType].fotaTjcl.disabled
    }
  },
  // 启用策略
  {
    title: i18n.t('start'),
    key: 'enabledStrategy',
    disabled (record) {
      // 已停用了的则显示
      return record.enabled
    },
    getAuth (record, vm) {
      return strategyPerms[vm.versionType][vm.upgradeTriggerType].fotaTjcl.disabled
    }
  },
  {
    title: i18n.t('delete'),
    key: 'deleteList',
    getAuth (record, vm) {
      return strategyPerms[vm.versionType][vm.upgradeTriggerType].fotaTjcl.delete
    },
    disabled (record) {
      // 条件策略当已使用则不能再删除
      return record.used
    }
  },
  // 复制策略
  {
    title: i18n.t('copy'),
    key: 'copyStrategy',
    getAuth (record, vm) {
      return strategyPerms[vm.versionType][vm.upgradeTriggerType].fotaTjcl.copy
    }
  }
]
